package com.lpit.exception;

import com.lpit.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常的捕获
 */
@ControllerAdvice
@Slf4j
public class GlobalException {

    @ExceptionHandler({AdminException.class})
    public String login(AdminException exception){
        log.info(exception.getLocalizedMessage());
        return "forward:/404.png";
    }

    @ExceptionHandler({NotLoginException.class})
    public String notLogin(NotLoginException exception){
        log.info(exception.getMessage());
        return "forward:/登录.html";
    }

//    @ExceptionHandler({Exception.class})
//    public String exception(Exception e){
//        log.info("未知错误{}",e.getMessage());
//        return "forward:/404.png";
//    }

    /*用户异常*/
    @ResponseBody
    @ExceptionHandler({UserException.class})
    public Result<String> UserException(UserException e){
        return Result.exception(e.getMessage());
    }

}
